﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


//using Ivy.Common.Framework.GeneralUtility;
using Hsmp.SocietyAdmin.IBusinessLogic;
using Hsmp.SocietyAdmin.BusinessLogic;
using Hsmp.SocietyAdmin.Entity;
using HSMPWeb.ViewEntity;
namespace HSMPWeb.Pages
{
    public partial class FlatListing : System.Web.UI.Page
    {
        #region  Variable & constant
        #endregion  Variable & constant

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        #region Properties
        #endregion Properties

        #region Public Methods
        #endregion Public Methods

        #region Events
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadFlatList();
            }
        }
        protected void btnRetrieveData_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/FlatDetails.aspx?FlatKey=" + this.TextBox1.Text);
        }
        #endregion Events

        #region Private Methods
        protected void LoadFlatList()
        {
            try
            {
                List<Flat> lFlatList = new List<Flat>();
                FlatRegistrationBus lFlatRegistrationBus = new FlatRegistrationBus();
                lFlatList = lFlatRegistrationBus.GetAllFlatList();

                gdvFlatList.DataSource = lFlatList;
                gdvFlatList.DataBind();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
        }

        protected void gdvFlatList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                List<Flat> lFlatList = new List<Flat>();
                FlatRegistrationBus lFlatRegistrationBus = new FlatRegistrationBus();
                lFlatList = lFlatRegistrationBus.GetAllFlatList();
                if (Session["lFlatList"] == null)
                {
                    var vlstFlat = lFlatRegistrationBus.GetAllFlatList();
                    lFlatList = ((from x in vlstFlat select x).OrderByDescending(x => x.FlatKey)).ToList();
                    Session["lstSociety"] = lFlatList;
                }
                else
                {
                    lFlatList = (List<Flat>)Session["lFlatList"];
                }

                gdvFlatList.DataSource = lFlatList;
                gdvFlatList.PageIndex = e.NewPageIndex;
                gdvFlatList.DataBind();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
        }
        #endregion Private Methods

        

        
    }
}